package leetcode.sword;

import java.util.Arrays;
import java.util.TreeMap;

public class Solution50 {

    public char firstUniqChar(String s) {
        int[] firstIdx = new int[26];
        Arrays.fill(firstIdx,-1);
        int[] times = new int[26];
        for(int i=0;i<s.length();i++){
            char c = s.charAt(i);
            int loc = c - 'a';
            times[loc]++;
            if(firstIdx[loc]==-1){
                firstIdx[loc] = i;
            }
        }
        int res = s.length();
        for(int i=0;i<26;i++){
            if(times[i]==1){
                res = Math.min(res,firstIdx[i]);
            }
        }
        return res == s.length()?' ':s.charAt(res);
    }
}
